﻿using System;
using SharpSqlAnalyzer.nodes;

namespace SharpSqlAnalyzer.stmt.postgresql
{
	// Token: 0x0200012A RID: 298
	public class TPostgresqlCreateFunction : TCommonStoredProcedureSqlStatement
	{
		// Token: 0x06000986 RID: 2438 RVA: 0x00303701 File Offset: 0x00301901
		public TPostgresqlCreateFunction(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstpostgresqlCreateFunction;
		}

		// Token: 0x170001AA RID: 426
		// (get) Token: 0x06000987 RID: 2439 RVA: 0x0030371C File Offset: 0x0030191C
		// (set) Token: 0x06000988 RID: 2440 RVA: 0x00303724 File Offset: 0x00301924
		public virtual int ReturnMode
		{
			get
			{
				return this.returnMode;
			}
			set
			{
				this.returnMode = value;
			}
		}

		// Token: 0x170001AB RID: 427
		// (get) Token: 0x06000989 RID: 2441 RVA: 0x0030372D File Offset: 0x0030192D
		// (set) Token: 0x0600098A RID: 2442 RVA: 0x00303735 File Offset: 0x00301935
		public virtual TTableElementList ReturnTableDefinitions
		{
			get
			{
				return this.returnTableDefinitions;
			}
			set
			{
				this.returnTableDefinitions = value;
			}
		}

		// Token: 0x170001AC RID: 428
		// (get) Token: 0x0600098B RID: 2443 RVA: 0x0030373E File Offset: 0x0030193E
		// (set) Token: 0x0600098C RID: 2444 RVA: 0x00303746 File Offset: 0x00301946
		public virtual TConstant ProcedureLanguage
		{
			get
			{
				return this.procedureLanguage;
			}
			set
			{
				this.procedureLanguage = value;
			}
		}

		// Token: 0x170001AD RID: 429
		// (get) Token: 0x0600098D RID: 2445 RVA: 0x0030374F File Offset: 0x0030194F
		// (set) Token: 0x0600098E RID: 2446 RVA: 0x00303757 File Offset: 0x00301957
		public virtual TObjectName OuterLabelName
		{
			get
			{
				return this.outerLabelName;
			}
			set
			{
				this.outerLabelName = value;
			}
		}

		// Token: 0x170001AE RID: 430
		// (get) Token: 0x0600098F RID: 2447 RVA: 0x00303760 File Offset: 0x00301960
		// (set) Token: 0x06000990 RID: 2448 RVA: 0x00303768 File Offset: 0x00301968
		public virtual TConstant LinkSymbol
		{
			get
			{
				return this.linkSymbol;
			}
			set
			{
				this.linkSymbol = value;
			}
		}

		// Token: 0x170001AF RID: 431
		// (get) Token: 0x06000991 RID: 2449 RVA: 0x00303771 File Offset: 0x00301971
		// (set) Token: 0x06000992 RID: 2450 RVA: 0x00303779 File Offset: 0x00301979
		public virtual TConstant Objfile
		{
			get
			{
				return this.objfile;
			}
			set
			{
				this.objfile = value;
			}
		}

		// Token: 0x06000993 RID: 2451 RVA: 0x00303784 File Offset: 0x00301984
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TCreateFunctionSqlNode tcreateFunctionSqlNode = (TCreateFunctionSqlNode)this.rootNode;
			if (base.doParseStatement(psql) != 0)
			{
				return -1;
			}
			this.functionName = tcreateFunctionSqlNode.FunctionName;
			base.DatabaseObjects.Add(this.functionName);
			this.procedureLanguage = tcreateFunctionSqlNode.ProcedureLanguage;
			this.outerLabelName = tcreateFunctionSqlNode.LabelName;
			this.objfile = tcreateFunctionSqlNode.Objfile;
			this.linkSymbol = tcreateFunctionSqlNode.LinkSymbol;
			if (tcreateFunctionSqlNode.ReturnDataType != null)
			{
				this.returnMode = 1;
				this.returnDataType = tcreateFunctionSqlNode.ReturnDataType;
			}
			else if (tcreateFunctionSqlNode.ReturnTable != null)
			{
				TDummy returnTable = tcreateFunctionSqlNode.ReturnTable;
				this.returnMode = 2;
				this.returnTableDefinitions = (TTableElementList)returnTable.list1;
				this.returnTableDefinitions.doParse(this, ESqlClause.unknown);
			}
			this.ParameterDeclarations = tcreateFunctionSqlNode.Parameters;
			if (this.ParameterDeclarations != null)
			{
				for (int i = 0; i < this.ParameterDeclarations.size(); i++)
				{
					this.TopStatement.SymbolTable.Push(new TSymbolTableItem(9, this, this.ParameterDeclarations.getParameterDeclarationItem(i)));
				}
			}
			if (tcreateFunctionSqlNode.DeclareStmts != null)
			{
				tcreateFunctionSqlNode.DeclareStmts.doParse(this, ESqlClause.unknown);
				for (int j = 0; j < tcreateFunctionSqlNode.DeclareStmts.size(); j++)
				{
					this.TopStatement.SymbolTable.Push(new TSymbolTableItem(10, this, tcreateFunctionSqlNode.DeclareStmts.getStatementSqlNode(j).Stmt));
					this.DeclareStatements.add(tcreateFunctionSqlNode.DeclareStmts.getStatementSqlNode(j).Stmt);
				}
			}
			if (tcreateFunctionSqlNode.Stmts != null)
			{
				tcreateFunctionSqlNode.Stmts.doParse(this, ESqlClause.unknown);
				for (int k = 0; k < tcreateFunctionSqlNode.Stmts.size(); k++)
				{
					this.BodyStatements.add(tcreateFunctionSqlNode.Stmts.getStatementSqlNode(k).Stmt);
				}
			}
			if (tcreateFunctionSqlNode.ExceptionClause != null)
			{
				tcreateFunctionSqlNode.ExceptionClause.doParse(this, ESqlClause.unknown);
				this.ExceptionClause = tcreateFunctionSqlNode.ExceptionClause;
			}
			if (tcreateFunctionSqlNode.DeclareStmts != null)
			{
				for (int l = 0; l < tcreateFunctionSqlNode.DeclareStmts.size(); l++)
				{
					this.TopStatement.SymbolTable.Pop();
				}
			}
			if (this.ParameterDeclarations != null)
			{
				for (int m = 0; m < this.ParameterDeclarations.size(); m++)
				{
					this.TopStatement.SymbolTable.Pop();
				}
			}
			return 0;
		}

		// Token: 0x170001B0 RID: 432
		// (get) Token: 0x06000994 RID: 2452 RVA: 0x003039E2 File Offset: 0x00301BE2
		// (set) Token: 0x06000995 RID: 2453 RVA: 0x003039EA File Offset: 0x00301BEA
		public virtual TObjectName FunctionName
		{
			get
			{
				return this.functionName;
			}
			set
			{
				this.functionName = value;
			}
		}

		// Token: 0x170001B1 RID: 433
		// (get) Token: 0x06000996 RID: 2454 RVA: 0x003039F3 File Offset: 0x00301BF3
		// (set) Token: 0x06000997 RID: 2455 RVA: 0x003039FB File Offset: 0x00301BFB
		public virtual TTypeName ReturnDataType
		{
			get
			{
				return this.returnDataType;
			}
			set
			{
				this.returnDataType = value;
			}
		}

		// Token: 0x170001B2 RID: 434
		// (get) Token: 0x06000998 RID: 2456 RVA: 0x00303A04 File Offset: 0x00301C04
		public override TObjectName StoredProcedureName
		{
			get
			{
				return this.functionName;
			}
		}

		// Token: 0x06000999 RID: 2457 RVA: 0x00303A0C File Offset: 0x00301C0C
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x0600099A RID: 2458 RVA: 0x00303A1C File Offset: 0x00301C1C
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.ParameterDeclarations != null)
			{
				this.ParameterDeclarations.accept(v);
			}
			if (this.DeclareStatements.size() > 0)
			{
				this.DeclareStatements.accept(v);
			}
			if (this.BodyStatements.size() > 0)
			{
				this.BodyStatements.accept(v);
			}
			if (this.ExceptionClause != null)
			{
				this.ExceptionClause.accept(v);
			}
			v.postVisit(this);
		}

		// Token: 0x0400124A RID: 4682
		private TObjectName outerLabelName;

		// Token: 0x0400124B RID: 4683
		private TObjectName functionName;

		// Token: 0x0400124C RID: 4684
		private TTypeName returnDataType;

		// Token: 0x0400124D RID: 4685
		private TConstant objfile;

		// Token: 0x0400124E RID: 4686
		private TConstant linkSymbol;

		// Token: 0x0400124F RID: 4687
		private int returnMode = 1;

		// Token: 0x04001250 RID: 4688
		private TTableElementList returnTableDefinitions;

		// Token: 0x04001251 RID: 4689
		private TConstant procedureLanguage;
	}
}
